package com.example.hdwx.myapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.example.hdwx.myapplication.R;
import com.example.hdwx.myapplication.eneity.found_eneitys.FoundActivityEneity;
import com.example.hdwx.myapplication.untils.ImageLoaderUtils;

import java.util.List;

/**
 * Created by hudongwx on 17-2-14.
 */

public class FoundActivityAdapter extends RecyclerView.Adapter<FoundActivityAdapter.FoundActivityHolder>{

    Context context;
    List<FoundActivityEneity> data;


    public FoundActivityAdapter(Context context, List<FoundActivityEneity> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public FoundActivityHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.found_item_activity_layout, parent, false);
        return new FoundActivityHolder(view);
    }

    @Override
    public void onBindViewHolder(FoundActivityHolder holder, int position) {
        final FoundActivityEneity eneity =data.get(position);

        holder.textView.setText(eneity.getName());
        ImageLoaderUtils.setImageLoader(context,eneity.getImageUrl(),holder.imageView);

        holder.linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 点击事件
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class FoundActivityHolder extends RecyclerView.ViewHolder{
        ImageView imageView;//图片
        TextView textView;//标题
        LinearLayout linearLayout; //点击事件
        public FoundActivityHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.found_activity);
            textView = (TextView) itemView.findViewById(R.id.found_text);
            linearLayout = (LinearLayout) itemView.findViewById(R.id.found_activity_layout);
        }
    }

}
